from django.core import exceptions
from django.utils.deprecation import MiddlewareMixin
from yushiapi.utils import resultResponse
from yushiapi.CommonLog import CommonLog

class MyFirstMiddleware(MiddlewareMixin):

    def process_request(self,request):
        #confirm login 
        if request.path == "/api/v1/yushiuser/" and request.method=="GET":
            pass 
        else:
            _id = request.session.get("union_id",None)
            if not _id:
                return resultResponse(201) 

    def process_response(self,request,response):
        return response

    def process_view(self,request,view_func,view_args,view_kwargs):
        pass 

    def process_exception(self,request,exception):
        #logging
        log = CommonLog()
        message = exception
        log.console(message)
        return resultResponse(502)